  window.onload=function(){
	var oPurchaseNum=document.getElementById("contentList");
	if(oPurchaseNum==null) return;
	var oSub=oPurchaseNum.getElementsByClassName("listInfo");
	var oPrice=oPurchaseNum.getElementsByClassName("presentPrice");
	var OriginalPrice=oPurchaseNum.getElementsByClassName("originalPrice");
	var oNum=oPurchaseNum.getElementsByClassName("sumNum");
	var oAll=document.getElementById("sumAll");
	var oBreaks=document.getElementById("breaks");
	for(var i=0;i<oSub.length;i++){
        totalAmount(oSub[i])
	}   
    function fn(){
    	var oSumAll=0;
    	for(var i=0;i<listInfo.length;i++){
    		oSumAll = oSumAll+ oPrice[i].innerHTML*oNum[i].value;
    	}
    	oAll.innerHTML=parseFloat(oSumAll);
    }
   fn();
    function preMonery(){
    	var oPreMonery=0;
    	for(var i=0;i<listInfo.length;i++){
    		oPreMonery = oPreMonery+parseInt(OriginalPrice[i].innerHTML)*oNum[i].value;
    	}
    	oBreaks.innerHTML=parseFloat(oPreMonery);

    }
    preMonery();
	$(function(){
		$('.delete').on("touchend",function(){
			$(this).parent().remove();
		})
	})
 function totalAmount(obj){
      var Subtra=obj.getElementsByClassName("Reduction01")[0];
      var oAdd=obj.getElementsByClassName("add")[0];
      var oSum=obj.getElementsByClassName("sumNum")[0];
	  //oSum.preventDefault();
      var m;
      var oPrice=oPurchaseNum.getElementsByClassName("presentPrice")[0].innerHTML;
		Subtra.addEventListener('click',function(){
		m=oSum.value;
		m--;
		if(m<0){
        m=0;
		} 
		else{
		oSum.value=m;
		fn();
		preMonery()
		}	
		})
		oAdd.addEventListener('click',function(){
		m=oSum.value;
		m++;	
		oSum.value=m;
		fn();
		preMonery();
		})
	oSum.onblur=function(){
		m=oSum.value;
		oSum.value=m;
		fn();
		preMonery();
	}
}
}
  	window.addEventListener('load',function(){
		var initX;
		var moveX;
		var X = 0;
		var objX = 0;
		var oContentList=document.getElementById("contentList");
		var touchstart=function(event){
			event.preventDefault();
			var obj = event.target.parentNode;
			if(obj.className == "listInfo clearfix"){
				initX = event.targetTouches[0].pageX;
				alert()
				objX =(obj.style.WebkitTransform.replace(/translateX\(/g,"").replace(/px\)/g,""))*1;
			}
			if( objX == 0){
				var touchmove=function(event) {
					event.preventDefault();
					var obj = event.target.parentNode;
					if (obj.className == "listInfo clearfix") {
						moveX = event.targetTouches[0].pageX;
						X = moveX - initX;
						console.log(X)
						if (X > 0) {
							obj.style.WebkitTransform = "translateX(" + 0 + "px)";
						}
						else if (X < 0) {
							var l = Math.abs(X);
							obj.style.WebkitTransform = "translateX(" + -l + "px)";
							if(l>120){
								l=120;
								obj.style.WebkitTransform = "translateX(" + -l + "px)";
							}
						}
					}
				}
				oContentList.addEventListener('touchmove',touchmove,false);
			}
			else if(objX<0){
				var touchmove=function(event) {
					event.preventDefault();
					var obj = event.target.parentNode;
					if (obj.className == "listInfo clearfix") {
						moveX = event.targetTouches[0].pageX;
						X = moveX - initX;
						if (X > 0) {
							var r = -120 + Math.abs(X);
							obj.style.WebkitTransform = "translateX(" + r + "px)";
							if(r>0){
								r=0;
								obj.style.WebkitTransform = "translateX(" + r + "px)";
							}
						}
						else {     //向左滑动
							obj.style.WebkitTransform = "translateX(" + -120 + "px)";
						}
					}
				}
				oContentList.addEventListener('touchmove',touchmove,false);
			}

		}

		oContentList.addEventListener('touchstart',touchstart,false)

		var touchend=function(event){
			event.preventDefault();
			var obj = event.target.parentNode;
			if(obj.className == "listInfo clearfix"){
				objX =(obj.style.WebkitTransform.replace(/translateX\(/g,"").replace(/px\)/g,""))*1;
				if(objX>-60){
					obj.style.WebkitTransform = "translateX(" + 0 + "px)";
				}else{
					obj.style.WebkitTransform = "translateX(" + -120 + "px)";
				}
			}
        this.removeEventListener("touchstart",touchstart,false);
		 }
		oContentList.addEventListener('touchend',touchend,false);
	})